/**
 * 基础菜单 差评申请
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>差评删除申请</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">

    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
       <el-table-column sortable prop="sellerNo" label="店铺编号" width="150">
      </el-table-column>
       <el-table-column sortable prop="orderNo" label="订单编号" width="150">
      </el-table-column>
      <el-table-column sortable prop="commentDetail" label="评论内容" width="300">
      </el-table-column>
      <el-table-column sortable
          label="分数"
          width="180">
        <template slot-scope="scope">
          <el-rate v-model="scope.row.serveCore" :allow-half="true"  disabled text-color="#ff9900"></el-rate>
        </template>
      </el-table-column>

      <el-table-column sortable prop="dataTime" label="评论时间" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>{{scope.row.dataTime|timestampToTime}}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button size="mini" @click="showPic(scope.$index, scope.row)">查看评论图片</el-button>
          <el-button size="mini"  type="danger" @click="coDelApply(scope.$index, scope.row)">通过</el-button>
          <el-button size="mini"  type="danger" @click="coDelFalse(scope.$index, scope.row)">驳回</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 编辑界面 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="50%" @click="closeDialog">
      <!-- <el-upload class="upload-demo"
        action="上传的地址"
        list-type="picture-card"
        :auto-upload="false"
        :file-list="fileList"
        ref="upload"
        :limit="limitCount"
        accept=".jpg, .jpeg, .png"
        >
      </el-upload> -->
      <viewer :images="fileList">
      <ul class="el-upload-list el-upload-list--picture-card" >
         <li tabindex="0" class="el-upload-list__item" v-for="item in fileList" :key="item">
           <img :src="item.url" alt class="el-upload-list__item-thumbnail">
        </li>
      </ul>
      </viewer>
       </el-dialog>
  </div>
</template>

<script>
import { sellerCommentList,commentDelApply,falseCommentDel } from '../../api/commentMG'
import Pagination from '../../components/Pagination'
import { objectToFormData } from 'object-to-formdata';
import { base64ToArrayBuffer} from '../../utils/util'


export default {
  data() {
    return {
      dictProType:[],
      fileList:[],
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      editForm: {
        no:'',
        productType:'',
        proName:'',
        amount:'',
        descri:'',
        sellerNo:''
      },
      // rules表单验证
      rules: {
        proName: [
          { required: true, message: '请输入商品名称', trigger: 'blur' }
        ],
        productType: [{ required: true, message: '请输入商品类型', trigger: 'blur' }],
        amount: [{ required: true, message: '请输入商品价格', trigger: 'blur' }],
      },
       formInline: {
        pageIndex: 1,
        pageSize: 10,
        sellerNo: '',
      },
      // 删除部门
      seletedata: {
        ids: ''
      },
      userparm: [], //搜索权限
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },
  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
     imageChange(file, fileList, name) {//on-change触发
        this.fileList = fileList
      },
      handleRmove(file,fileList,name){
        this.fileList = []
      },
   
    // 获取公司列表
    getdata(parameter) {
      this.loading = true
      // 模拟数据结束

      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
      sellerCommentList(parameter)
        .then(res => {
          this.loading = false
          if (res.code == '0') {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            let datas = res.data.datas;
            for(let i = 0;i<datas.length;i++){
              let photos = datas[i].photos
              for(let j =0;j<photos.length;j++){
                 photos[j].photo = 'data:image/png;base64,'+photos[j].photo;
              }
            }
            this.listData = res.data.datas
            // 分页赋值
            this.pageparm.currentPage = this.formInline.pageIndex
            this.pageparm.pageSize = this.formInline.pageSize
            this.pageparm.total = res.data.total
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('评论加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    //显示编辑界面
    showPic: function(index, row) {
      let photos = row.photos;
      this.fileList = [];
      this.editFormVisible = true
      if (row != undefined && row != 'undefined') {
        this.title = '评论图片'
        for(let i= 0;i<photos.length;i++){
          let p = photos[i].photo;
          let obj = new Object();
          obj.url = p ;
          this.fileList.push(obj)
        }
       
      }
    },
    // 删除
    coDelApply(index, row) {
      this.$confirm('确定要删除吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let param = {
            no:row.no
          }
          commentDelApply(param)
            .then(res => {
              if (res.code == '1') {
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                })
                this.getdata(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('删除失败，请稍后再试！')
            })
        })
    },
    // 驳回
    coDelFalse(index, row) {
      this.$confirm('确定要驳回吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let param = {
            no:row.no
          }
          falseCommentDel(param)
            .then(res => {
              if (res.code == '1') {
                this.$message({
                  type: 'success',
                  message: '驳回成功!'
                })
                this.getdata(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('驳回失败，请稍后再试！')
            })
        })
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}

</style>

 
 